package com.example.service.webhook.business.insurance.repository;

import javax.annotation.Resource;

import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.example.service.webhook.business.insurance.entity.InsurancePolicyBaseInfoEntity;
import com.example.service.webhook.repository.base.BaseDAO;
import com.example.service.webhook.util.DateUtil;
/**
 * 
 * ClassName: InsurancePolicyBaseInfoRepository    
 * date: 2017年1月11日 下午10:18:15   
 * @author yuandong  
 * @version   
 * @since JDK 1.6
 */
@Repository
public class InsurancePolicyBaseInfoRepository extends BaseDAO<InsurancePolicyBaseInfoEntity>{
	
	@Resource(name="templateInsurance")
    private JdbcTemplate jdbcTemplate;

    public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}
    
    public void saveInsurancePolicyBaseInfo(InsurancePolicyBaseInfoEntity entity) throws Exception  {
    	entity.setCreateTime(DateUtil.getCurrentDate());
    	entity.setLastModifyTime(DateUtil.getCurrentDate());
		this.add(entity);
    }
    
    public void updateInsurancePolicyBaseInfo(InsurancePolicyBaseInfoEntity entity) throws Exception  {
    	entity.setLastModifyTime(DateUtil.getCurrentDate());
		this.modify(entity);
    }
    
    public InsurancePolicyBaseInfoEntity getInsurancePolicyBaseInfo(String userId,String mappingId,String policyNum) throws Exception {
        String sql = "";
        String tableName = "t_insurance_policy_baseinfo";
        sql = "select * from " + tableName + " where userId=? and mappingId=? and policyNum=?";
        InsurancePolicyBaseInfoEntity pojo = null;
        try{
         pojo = (InsurancePolicyBaseInfoEntity) queryOne(sql, new Object[] { userId,mappingId,policyNum }, new InsurancePolicyBaseInfoEntity());	
        }catch(EmptyResultDataAccessException e){
        	return null;
        }
        
        return pojo;
    }
    
    
}
